{% extends "layout/basic.html" %}
{% import "components/contest.html" as contest with context %}
{% import "components/record.html" as record with context %}
{% import "components/problem.html" as problem with context %}
{% block content %}
{{ set(UiContext, 'tdoc', tdoc) }}
{{ set(UiContext, 'tsdoc', tsdoc) }}
{% set hasCorrection = correction and Object.keys(correction).length %}
<div class="row" data-sticky-parent>
  <div class="medium-9 columns">
    <div class="section">
      <div class="section__header">
        <h1 class="section__title">{{ _('Problems') }}</h1>
      </div>
      <div class="section__body no-padding">
        <table class="data-table">
          <colgroup>
          {% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %}
            <col class="col--status">
            <col class="col--submit-at">
          {% endif %}
          {% if showScore %}
            <col class="col--score">
          {% endif %}
            <col class="col--problem">
          </colgroup>
          <thead>
            <tr>
            {% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %}
              <th class="col--status record-status--border">{{ _('Status') }}</th>
              {% if hasCorrection %}
                <th class="col--correction">{{ _('Correction') }}</th>
              {% else %}
                <th class="col--submit-at">{{ _('Last Submit At') }}</th>
              {% endif %}
            {% endif %}
            {% if showScore %}
              <th class="col--score">{{ _('Score') }}</th>
            {% endif %}
              <th class="col--problem">{{ _('Problem') }}</th>
            </tr>
          </thead>
          <tbody>
          {%- for pid in tdoc.pids -%}
            <tr>
            {% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %}
              {% if psdict[pid] and psdict[pid].rid %}
                {% set rdoc = rdict[psdict[pid].rid] %}
                {% if model.contest.canShowSelfRecord.call(handler, tdoc) %}
                  {% set displayScore = ((tdoc.score[pid]|default(100)) * (psdict[pid].score|default(0)) / 100) if showScore else (psdict[pid].penaltyScore|default(psdict[pid].score)) %}
                  {{ record.render_status_td(rdoc, displayScore=displayScore) }}
                {% else %}
                  <td class="col--status record-status--border"><a href="{{ url('record_detail', rid=rdoc._id) }}">{{ _('Submitted') }}</a></td>
                {% endif %}
                {% if not hasCorrection %}
                  <td class="col--submit-at">{{ datetimeSpan(rdoc._id)|safe }}</td>
                {% endif %}
              {% else %}
                <td class="col--status record-status--border">{{ _('No Submissions') }}</td>
                {% if not hasCorrection %}
                  <td class="col--submit-at">-</td>
                {% endif %}
              {% endif %}
              {% if hasCorrection %}
                {% if correction[pid] %}
                  {{ record.render_status_td(rdict[correction[pid].rid], class="col--correction") }}
                {% else %}
                  <td class="col--correction">-</td>
                {% endif %}
              {% endif %}
            {% endif %}
            {% if showScore %}
              <td class="col--score">{{ tdoc.score[pid]|default(100) }}</td>
            {% endif %}
              <td class="col--problem col--problem-name">
                {{ problem.render_problem_title(pdict[pid], tdoc, alphabetic=true) }}
                {% if pdict[pid].config.type != 'objective' and pdict[pid].config.type != 'submit_answer' %}
                  <span class="problem__tag-item icon icon-stopwatch" style="font-size: .75rem;margin: 0;padding: 0 5px!important;">{{ pdict[pid].config.timeMax if pdict[pid].config.timeMax == pdict[pid].config.timeMin else pdict[pid].config.timeMin+'~'+pdict[pid].config.timeMax }}ms</span>
                  <span class="problem__tag-item icon icon-comparison" style="font-size: .75rem;margin: 0;padding: 0 5px!important;">{{ pdict[pid].config.memoryMax if pdict[pid].config.memoryMax == pdict[pid].config.memoryMin else pdict[pid].config.memoryMin+'~'+pdict[pid].config.memoryMax }}MiB</span>
                {% endif %}
                {% if pdict[pid].config.type != 'objective' %}
                  <a href="{{ url('problem_submit', pid=pid, query={tid:tdoc.docId}) }}" target="_blank" class="typo-a" style="float: right;"><span class="icon icon-send">{{ _('Submit') }}</span></a>
                {% endif %}
              </td>
            </tr>
          {%- endfor -%}
          </tbody>
        </table>
      </div>
    </div>
    <div class="section">
      <div class="section__header">
        <h1 class="section__title">{{ _('Submissions') }}</h1>
      </div>
      <div class="section__body no-padding">
      {% if not canViewRecord %}
        {{ nothing.render('According to the contest rules, you cannot view your submission details at current.', compact=true) }}
      {% elif not rdocs.length %}
        {{ nothing.render('Oh, there is no submission!', compact=true) }}
      {% else %}
        <table class="data-table record_main__table">
          <colgroup>
            <col class="col--status">
            <col class="col--problem">
            <col class="col--submit-by">
            <col class="col--time">
            <col class="col--memory">
            <col class="col--lang">
            <col class="col--submit-at">
          </colgroup>
          <thead>
            <tr>
              <th class="col--status record-status--border">{{ _('Status') }}</th>
              <th class="col--problem">{{ _('Problem') }}</th>
              <th class="col--submit-by">{{ _('Submit By') }}</th>
              <th class="col--time">{{ _('Time') }}</th>
              <th class="col--memory">{{ _('Memory') }}</th>
              <th class="col--lang">{{ _('Language') }}</th>
              <th class="col--submit-at">{{ _('Submit At') }}</th>
            </tr>
          </thead>
          <tbody>
          {%- for rdoc in rdocs -%}
            {% set udoc = udict[rdoc['uid']] %}
            {% set pdoc = pdict[rdoc['pid']] %}
            {% include 'record_main_tr.html' %}
          {%- endfor -%}
          </tbody>
        </table>
      {% endif %}
      </div>
    </div>
    <div class="section section--clarifications">
      <div class="section__header">
        <h1 class="section__title">{{ _('Contest Clarifications') }}</h1>
      </div>
      <div class="section__body">
      {% if not tcdocs.length %}
        {{ nothing.render('Oh, there is no clarification!', compact=true) }}
      {% else %}
      <ul class="dczcomments__list">
        {% for doc in tcdocs %}
        <li class="dczcomments__item">
          <div class="media">
            <div class="media__body top">
              <div class="clearfix">
                <div class="supplementary dczcomments__supplementary">
                  {{_('Subject') }}: {{ contest.render_clarification_subject(tdoc,pdict,doc.subject) }} | {% if doc.owner == 0 %}<b>{{ _('Jury') }}</b>{% else %}{{ user.render_inline(udict[doc.owner], badge=false) }}{% endif %} @ {{ datetimeSpan(doc._id)|safe }}
                </div>
              </div>
              <div class="typo richmedia" data-emoji-enabled>
                {{ doc['content']|markdown|safe }}
              </div>
            </div>
          </div>
          <ul class="dczcomments__replies">
          {%- for rdoc in doc['reply'] -%}
            <li class="dczcomments__reply">
              <div class="media">
                <div class="media__left top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
                <div class="media__body top">
                  <div class="clearfix">
                    <div class="supplementary dczcomments__supplementary">
                      <b>{{ _('Jury') }}</b> @ {{ datetimeSpan(rdoc['_id'])|safe }}
                    </div>
                  </div>
                  <div class="typo richmedia" data-emoji-enabled>
                    {{ rdoc['content']|markdown|safe }}
                  </div>
                </div>
              </div>
            </li>
          {%- endfor -%}
          </ul>
        </li>
        {% endfor %}
      </ul>
      {% endif %}
      </div>
      {% if tsdoc.attend %}
      <div class="section__header">
        <h1 class="section__title">{{ _('Send Clarification Request') }}</h1>
      </div>
      <div class="section__body typo">
        <form method="post">
          <input type="hidden" name="operation" value="clarification">
          <div class="row">
            <div class="medium-12 columns form__item">
              <label>
                {{ _('Subject') }}
                <select name="subject" class="select">
                  <option value="0">{{ _('General Issue') }}</option>
                  <option value="-1">{{ _('Technical Issue') }}</option>
                  {% for pid in tdoc.pids %}
                  <option value="{{ pid }}">{{ utils.getAlphabeticId(loop.index0) }}. {{ pdict[pid].title }}</option>
                  {% endfor %}
                </select>
              </label>
            </div>
            <div class="medium-12 columns form__item">
              <label>
                {{ _('Content') }}
                <textarea name="content" class="textbox" data-markdown required></textarea>
              </label>
            </div>
          </div>
          <button type="submit" class="rounded primary button">{{ _('Submit') }}</button>
      </div>
      {% endif %}
    </div>
  </div>
  <div class="medium-3 columns" data-sticky="large">
    {% if tdoc.privateFiles.length %}
    <div class="section side">
      <div class="section__header">
        <h1 class="section__title">{{_('Materials')}}</h1>
      </div>
      <ol>
        {% for file in tdoc.privateFiles %}
        <li class="menu__item">
          <a class="menu__link" href="{{ url('contest_file_download', { tid: tdoc.docId, filename: file.name, type: 'private' }) }}">{{ file.name }}</a>
        </li>
        {% endfor %}
      </ol>
    </div>
    {% endif %}
    {% set owner_udoc = udict[tdoc.owner] %}
    {% include "partials/contest_sidebar.html" %}
  </div>
</div>
{% endblock %}